// pages/makeResume/makeResume.js
import { request, toast } from '../../utils/wxCommon'
const commonList = [
  {name:'',label:'工作公司：', placeholder:"请输入单位名称", type:'text'},
  {name:'',label:'职位：', placeholder:"请输入公司职位", type:'text'},
  {name:'',label:'项目名：', placeholder:"请输入做过的项目", type:'text'},
  {name:'',label:'项目描述：', placeholder:"请简单描述下当前项目", type:'textarea'},
  {name:'',label:'技术栈：', placeholder:"请输入当前项目使用到的技术", type:'text'},
  {name:'',label:'责任描述：', placeholder:"请输入你在当前项目中都做了那些", type:'textarea'},
]
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:[
      {name:'',label:'姓名：', placeholder:"请输入姓名", type:'text'},//姓名
      {name:'',label:'年龄：', placeholder:"请输入年龄", type:'text'},//姓名
      {name:'',label:'民族：', placeholder:"请输入民族", type:'text'},//
      {name:'',label:'出生年月：', placeholder:"请输入出身日期", type:'text'},//出生年月：
      {name:'',label:'政治面貌：', placeholder:"请输入", type:'text'},//
      {name:'',label:'QQ：', placeholder:"请输入qq号", type:'number'},//
      {name:'',label:'联系电话：', placeholder:"请输入手机号", type:'number'},//
      {name:'',label:'E-Mail：', placeholder:"请输入邮箱号", type:'text'},//
      {name:'',label:'wx：', placeholder:"请输入wx", type:'text'},//
      {name:'',label:'博客：', placeholder:"请输入博客号", type:'text'},//
      {name:'',label:'工作年限：', placeholder:"请输入工作年限", type:'text'},//
      {name:'',label:'毕业开始及结束时间：', placeholder:"请输入毕业开始及结束时间", type:'text'},//
      {name:'',label:'学校：', placeholder:"请输入学校名", type:'text'},//
      {name:'',label:'学历：', placeholder:"请输入最高学历", type:'text'},//
      {name:'',label:'专业：', placeholder:"请输入专业", type:'text'},//
      {name:'',label:'求职状态：', placeholder:"请输入当前是否在/离职", type:'text'},//
      {name:'',label:'求职意向：', placeholder:"请输入求职意向", type:'text'},//
      {name:'',label:'自我介绍：', placeholder:"简单明了的介绍下自己", type:'textarea'},//
    ],
    skill:[{name:'',label:'技能特长：', placeholder:"请依次输入", type:'textarea'}],
    workExperience: [commonList],
    num: 1
  },
  //添加工作经历
  addList(){
    this.data.workExperience[this.data.num] = commonList;
    this.data.num++
    this.setData({
      workExperience: this.data.workExperience
    })
  },
  //删除当前的工作经历列表
  removeList(e){
    const index = e.currentTarget.dataset.index;
    this.data.workExperience[index] = [];
    this.setData({
      workExperience: this.data.workExperience
    })
  },
  //普通数据的
  onChange(e){
    console.log(e)
    const val = e.detail;
    const index = e.currentTarget.dataset.type
    this.data.userInfo[index].name = val;
  },
  //工作经历的
  onChange1(e){
    const parentIndex = e.currentTarget.dataset.index;
    const childIndex = e.currentTarget.dataset.type;
    const val = e.detail;
    this.data.workExperience[parentIndex][childIndex].name = val
  },
  //技能特长
  onChange2(e){
    const val = e.detail;
    this.data.skill[0].name = val
  },
  //进行提交数据到数据库
  submit(){
    const data = this.data.workExperience.filter(item=>item.length!=0);
    console.log(data);
    const params = {
      type: 9,
      openid: wx.getStorageSync('usreInfo').openid,
      list:{
        workExperience: data,
        userInfo: this.data.userInfo,
        skill: this.data.skill
      }
    }
    request('user',params).then(res=>{
      console.log(res);
      if(res.result.status === 'S'){
        toast(res.result.message);
        setTimeout(() => {
          wx.navigateBack({
            delta: 1,
          })
        }, 2000);
      }
    }).catch(msg=>{
      console.log(msg);
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})